﻿<Page
    x:Name="PageRoot"
    x:Class="Skrape.PageView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Skrape"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.PrimaryCommands>
                <AppBarButton Icon="Home" Label="Home" Command="{Binding Source={StaticResource GlobalResources}, Path=GoHomeCommand}"/>
                <AppBarButton Icon="Copy" Label="Copy" Command="{Binding Source={StaticResource GlobalResources}, Path=CopyCommand}"/>
                <AppBarButton Icon="Paste" Label="Paste" Command="{Binding Source={StaticResource GlobalResources}, Path=PasteCommand}"/>
                <AppBarButton Icon="Download" Label="Download" Command="{Binding Source={StaticResource GlobalResources}, Path=DownloadCommand}"/>
            </CommandBar.PrimaryCommands>
            <CommandBar.SecondaryCommands>
                <AppBarButton Icon="Favorite" Label="Set" Command="{Binding Source={StaticResource GlobalResources}, Path=FavoriteCommand}"/>
                <AppBarButton Icon="Save" Label="Save" Command="{Binding Source={StaticResource GlobalResources}, Path=SaveCommand}"/>
                <AppBarButton Icon="Add" Label="Add" Command="{Binding Source={StaticResource GlobalResources}, Path=AddCommand}"/>
                <AppBarButton Icon="Refresh" Label="Refresh" Command="{Binding Source={StaticResource GlobalResources}, Path=RefreshCommand}"/>
                <AppBarButton Icon="Delete" Label="Delete" Command="{Binding Source={StaticResource GlobalResources}, Path=DeleteCommand}"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" DataContext="{Binding Source={StaticResource GlobalResources}, Path=DataManager.CurrentPage}">
        <Grid.Resources>
            <Style TargetType="Image" 
                   x:Key="ThumbnailStyle">
                <Setter Property="Width" Value="150"/>
                <Setter Property="Height" Value="150"/>
                <Setter Property="HorizontalAlignment" Value="Center"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Stretch" Value="UniformToFill"></Setter>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <AppBarButton Click="BackButton_OnClick" IsEnabled="{Binding Frame.CanGoBack, ElementName=PageRoot}" Icon="Back"/>
        <Grid Grid.Row="1"
              Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="270"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <ToggleSwitch x:Name="ToggleHtml" 
                              IsEnabled="False"
                              OffContent="HTML"
                              OnContent="Text"
                              Toggled="ToggleSwitch_OnToggled"/>
                <TextBlock Grid.Row="1"
                           Margin="6"
                           Text="Thumbnail"
                           Style="{StaticResource SubtitleTextBlockStyle}"/>
                <Image Style="{StaticResource ThumbnailStyle}"
                       Grid.Row="2"
                       Source="{Binding ThumbnailPath}"/>
                <TextBlock Grid.Row="3"
                           Margin="6"
                           Text="Images"
                           Style="{StaticResource SubtitleTextBlockStyle}"/>
                <FlipView SelectionChanged="FlipViewOnSelectionChanged"
                          HorizontalAlignment="Center"
                          Height="200"
                          VerticalAlignment="Top"
                          Grid.Row="4"
                          ItemsSource="{Binding Images}">
                    <FlipView.ItemTemplate>
                        <DataTemplate>
                            <Image Style="{StaticResource ThumbnailStyle}"
                                   Source="{Binding}"></Image>
                        </DataTemplate>
                    </FlipView.ItemTemplate>
                </FlipView>
            </Grid>
            <WebView Grid.Column="1" 
                     Margin="10" 
                     x:Name="WebControl"
                     Visibility="Collapsed"></WebView>
            <ScrollViewer x:Name="TextControl" 
                          Grid.Column="1"
                          HorizontalAlignment="Stretch"
                          Margin="10">
                <TextBlock Margin="5"
                           HorizontalAlignment="Stretch"
                           VerticalAlignment="Stretch"
                           Text="{Binding Text}"
                           TextWrapping="Wrap"
                           Style="{StaticResource BodyTextBlockStyle}"/>
            </ScrollViewer>
            <ProgressBar Grid.Column="1"
                         Margin="10"
                         x:Name="LoadingIndicator"
                         IsIndeterminate="True"
                         Height="10">
            </ProgressBar>
        </Grid>
        <TextBlock Grid.Column="1"
                Text="{Binding Title}"
                Style="{StaticResource HeaderTextBlockStyle}"
                Margin="0, 0, 0, 40"/>
        <Rectangle x:Name="DeleteCover" 
                   Grid.Row="1"
                   Grid.Column="1"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Stretch"
                   Visibility="Collapsed"
                   Fill="{StaticResource ApplicationPageBackgroundThemeBrush}"/>
        <TextBlock x:Name="DeleteText" 
                   Text="The Skrape has been Deleted."
                   Grid.Row="1"
                   Grid.Column="1"
                   Visibility="Collapsed"
                   Style="{StaticResource SubheaderTextBlockStyle}"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"></TextBlock>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="PageViewStates">
                <VisualState x:Name="LoadingState"/>
                <VisualState x:Name="DeletedState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteCover"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteText"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="LoadedState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingIndicator"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="WebControl"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="ContentToggle">
                <VisualState x:Name="HtmlState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextControl"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="WebControl"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="TextState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextControl"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="WebControl"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>